





/*

Table B24

*/


local nametable = "tables/rev_cropchoicemarket"


use "public_data/g30.dta", clear


forvalues xd=1(1)1{
	
	if `xd'==1{
		local xdist = 50
	}


	*-----
	eststo clear
	local column_number = 1
	local column_name = "column" + "`column_number'"
	*---	
	

forvalues xcrop = 1(1)6{


use "public_data/g30.dta", clear

replace weight = 1
gen interdep =.
gen inter = .



if `xcrop'==1{
	replace interdep = cocoacoffeetea_areat>0
	local crop1			=			"Cocoa,"
	local crop2			=			"coffee,"
	local crop3			=			"tea"

}
if `xcrop'==2{
	replace interdep = groundnut_areat>0
	local crop1			=				"Groundnut"
	local crop2			=						" "
	local crop3			=				" "

}
if `xcrop'==3{
	replace interdep = bancocon_areat+ sugarbeet_areat+sugarcane_areat>0
	local crop1			=				"Banana,"
	local crop2			=					"coconut,"
	local crop3			=				"sugar crops"

}
if `xcrop'==4{
	
	replace interdep = oilpalm_areat+ olive_areat+rapeseed_areat+soybean_areat+sunflower_areat>0
	local crop1			=					"Oilpalm"
	local crop2			=					"and other"
	local crop3			=						"oil crops"

}


if `xcrop'==5{
	
	replace interdep = grownusa
	local crop1			=					"Best crop"
	local crop2			=					"under"
	local crop3			=					"US prices"

}

if `xcrop'==6{
	
	replace interdep = grownother
	local crop1			=						"Best crop"
	local crop2			=						"under"
	local crop3			=						"French prices"

}




	*computes the mean of the dependent var
	egen interm = mean(interdep)
	local vmeandep = interm[1]
	local meandep = string(`vmeandep')
	if index("`meandep'",".")==1{
		local meandep = "0"+substr("`meandep'",1,3)
	}
	if index("`meandep'",".")<5&index("`meandep'",".")>1{
		local meandep = substr("`meandep'",1,4)
	}
	

	*computes the number of country pairs
	egen intercp = group(border)	
	egen intercpmax = max(intercp)
	local countrypair = intercpmax[1]
	drop intercp*
	

*	xi: areg interdep  rdist1* varofi   [aw=weight],a(groupfe) cluster(border)
	reghdfe interdep rdist1*  varofi [aw=weight], absorb(groupfe) vce(cluster groupfe country)
	eststo `column_name'
	estadd local space  					" "
	estadd local maxdist 					"`xdist'"
	estadd local polynomial				"Linear"
	estadd local groupfe				"Yes"
	estadd local countrypair						"`countrypair'"
	estadd local crop1						"`crop1'"
	estadd local crop2						"`crop2'"
	estadd local crop3						"`crop3'"
	estadd local nmeandep				"`meandep'"
	local column_number = `column_number' + 1
	local column_name = "column" + "`column_number'"

	
}


label var interdep  " "		

local nametable1 = "`nametable'" + "`xd'" + ".tex"
#delimit ;
esttab column1 column2 column3 column4 column5 column6
using "`nametable1'",  replace
label
b(3)
se(3)
star(* 0.10 ** 0.05 *** 0.01)
width(1.0\hsize)
nonotes
nolines
noconstant
mgroups(  "\textit{Dep. Var.: Crop is grown}" , pattern(1 0 0 0 0 0)
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
 keep(varofi)
order(varofi)
  stats(groupfe					space	polynomial			space	r2		N					countrypair			space	maxdist							space	crop1		crop2	crop3	space	nmeandep,
    fmt(0						0		0					0		3		0					0					0		0								0		0			0		0		0		0)
layout(@						@		@					@		@		@					@					@		@								@		@			@		@		@		@)	 	
labels("Border x Ethnic FE"		" "		"RD polynomial"		" "		"R2"	"\# Observations" 	"\# Country pairs"	" "		"Max distance to border (km)"	" "		"Crop"		" "		" "		" "		"Mean Dep. Var.")
 )	
noobs
booktabs
;
#delimit cr

}









